﻿using BW.EatRabbit.API.Application.Commands.Breeding;
using BW.EatRabbit.API.Dtos;
using BW.EatRabbit.Domain;
using BW.EatRabbit.ErrorCode;
using BW.EatRabbit.Infrastructure.Interfaces;
using MediatR;

namespace BW.EatRabbit.API.Application.CommandHandlers.Breeding
{
    public class GetBreedingQueryCommandHandler : IRequestHandler<GetBreedingQueryCommand, APIResult<Breeding_Information>>
    {
        private readonly IBaseRepository<Breeding_Information> _breedingRepository;
        public GetBreedingQueryCommandHandler(IBaseRepository<Breeding_Information> breedingRepository)
        {

            _breedingRepository = breedingRepository;
        }
        public Task<APIResult<Breeding_Information>> Handle(GetBreedingQueryCommand request, CancellationToken cancellationToken)
        {
            APIResult<Breeding_Information> result = new APIResult<Breeding_Information>();

            var list= _breedingRepository.GetAll().FirstOrDefault(x=>x.ProductionBatch==request.ProductionBatch);
            if(list==null)
            {
                result.Code = ResultCode.查询失败;
                result.Message = "没有该条信息";
                return Task.FromResult(result);
            }

            result.Data = list;
           result.Code = ResultCode.查询成功;
            result.Message = ResultCode.查询成功.ToString();
            return Task.FromResult(result);
        }
    }
}
